<?php
namespace Admin\Controller;
use Think\Controller;
class CompanyController extends BaseController {
    public function index(){
    	$company=M('company');
        $companylist=$company->select();
        $this->assign("companylist",$companylist);	
    	$this->login_verify();
        $this->display();
    }
    public function addCompany(){
	    	// var_dump($_POST);
	    	$class=M('company');
	    	$data['name']=$_POST['name'];
	    	$data['content']=$_POST['content'];
	   		$data['time']=date('Y-m-d H:i:s');
	    	// var_dump($_FILES);
		    $upload = new \Think\Upload();// 实例化上传类
		    $upload->maxSize   =     2097152 ;// 设置附件上传大小
		    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		    $upload->saveName = 'time';
		    $upload->subName = 'company';
		    $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
		    // 上传单个文件 
		    $info   =   $upload->uploadOne($_FILES['company']);
		    if(!$info) {// 上传错误提示错误信息
		        $this->error($upload->getError());
		    }else{// 上传成功 获取上传文件信息
		    $data['imgurl']='Uploads/'.$info['savepath'].$info['savename'];	       
	    	if($class->add($data)){
	    		$this->success('添加成功', U('Company/index'));
	    	}else{
	    		$this->error('添加失败');
	    	}
	    }
	}

        // 删除操作
        public function companyDel(){
        $id=I('get.id');
        $company=M('company');
        if($company->where('id='.$id)->delete()){
                $this->success("删除成功",U('Company/index'));
        }else{
                $this->error("删除失败");
        }
    
    }
}    